package com.winkey.facility.gateway.service.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author yiyingzai
 */
public class DateArraysFormatUtil {

    public static int[] formatDate(String timeString){
        int[] timeResult = new int[6];
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = simpleDateFormat.parse(timeString);
            calendar.setTime(date);
            int year = calendar.get(Calendar.YEAR);
            timeResult[0] = year;
            int month = calendar.get(Calendar.MONTH)+1;
            timeResult[1] = month;
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            timeResult[2] = day;
            int hour = calendar.get(Calendar.HOUR);
            timeResult[3] = hour;
            int minute = calendar.get(Calendar.MINUTE);
            timeResult[4] = minute;
            int second = calendar.get(Calendar.SECOND);
            timeResult[5] = second;

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timeResult;
    }
}
